<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item>
        <el-input
          v-model="queryParams.className"
          placeholder="请输入排班名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-select
          v-model="queryParams.classAffiliation"
          placeholder="请选择部门"
          clearable
          @change="handleQuery"
        >
          <el-option
            v-for="item in getDept"
            :key="item.deptId"
            :label="item.deptName"
            :value="item.deptId"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-apply"
          size="mini"
          @click="handleMange"
          v-hasPermi="['eamp:list:mange']"
          >排班申请<i class="el-icon-upload el-icon--right"></i
        ></el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['eamp:class_manage:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['eamp:class_manage:export']"
          >导出</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="class_manageList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="classId" />
      <el-table-column label="排班名称" align="center" prop="className" />


      <el-table-column label="所属部门" align="center" prop="sysDept.deptName">
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="classCreatePeople" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="classCreateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.classCreateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleview(scope.row)"
            v-hasPermi="['eamp:class_manage:view']"
            >查看</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['eamp:class_manage:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
   <!-- 查看排班 -->
    <el-dialog
      title="排班申请"
      :visible.sync="viewMange"
      width="800px"
      append-to-body
      :style="{ 'text-align': 'center' }"
    >
      <el-form ref="viewForm" :model="viewForm" label-width="80px">
        <el-form-item label="排班名称">
          <el-input
            v-model="viewForm.className"
            placeholder="请输入排班名称"
            disabled></el-input>
        </el-form-item>
        <table>
          <tr>
            <td>
              <el-form-item label="紧急程度"> </el-form-item>
            </td>
            <td>
              <el-form-item label-width="20px">
                <el-select
                  v-model="viewForm.classUrgent"
                  placeholder="选择等级"
                  disabled>
                  <el-option label="A级" value="1"></el-option>
                  <el-option label="B级" value="2"></el-option>
                  <el-option label="C级" value="3"></el-option>
                </el-select>
              </el-form-item>
            </td>
            <td>
              <el-form-item label="部门"> </el-form-item>
            </td>
            <td>
              <el-form-item label-width="20px">
                <el-select
                  v-model="viewForm.classAffiliation"
                  placeholder="选择部门"
                  disabled>
                  <el-option
                    v-for="item in getDept"
                    :key="item.deptId"
                    :label="item.deptName"
                    :value="item.deptId"
                  ></el-option>
                </el-select>
              </el-form-item>
            </td>
          </tr>
        </table>
        <table class="dateTable">
          <tr v-for="(eve, info) in 7" :key="info">
            <td>日期</td>
            <td>
              <el-date-picker
                v-model="viewForm.dateList[info]"
                type="date"
                placeholder="选择日期"
                disabled>
              </el-date-picker>
            </td>
            <td>值班人</td>
            <td>
              <el-select
                v-model="viewForm.affactionList[info]"
                multiple
                placeholder="请选择值班人"
                disabled>
                <el-option
                  v-for="item in createPeople"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </td>
          </tr>
          <td>备注</td>
          <td>
            <el-input
              v-model="viewForm.classRemark"
              placeholder="请输入备注"
              disabled></el-input>
          </td>
          <td>附件</td>
          <td>
            <el-form-item>
              <file-upload v-model="viewForm.classAnnex" />
            </el-form-item>
          </td>
        </table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="manCancel">取 消</el-button>
      </div>
    </el-dialog>




  
  
   

    <!-- 排班申请 -->
    <el-dialog
      title="排班申请"
      :visible.sync="applymange"
      width="800px"
      append-to-body
      :style="{ 'text-align': 'center' }"
    >
      <el-form ref="applyForm" :model="applyForm" label-width="80px">
        <el-form-item label="排班名称">
          <el-input
            v-model="applyForm.className"
            placeholder="请输入排班名称"
          ></el-input>
        </el-form-item>
        <table>
          <tr>
            <td>
              <el-form-item label="紧急程度"> </el-form-item>
            </td>
            <td>
              <el-form-item label-width="20px">
                <el-select
                  v-model="applyForm.classUrgent"
                  placeholder="选择等级"
                >
                  <el-option label="A级" value="1"></el-option>
                  <el-option label="B级" value="2"></el-option>
                  <el-option label="C级" value="3"></el-option>
                </el-select>
              </el-form-item>
            </td>
            <td>
              <el-form-item label="部门"> </el-form-item>
            </td>
            <td>
              <el-form-item label-width="20px">
                <el-select
                  v-model="applyForm.classAffiliation"
                  placeholder="选择部门"
                >
                  <el-option
                    v-for="item in getDept"
                    :key="item.deptId"
                    :label="item.deptName"
                    :value="item.deptId"
                  ></el-option>
                </el-select>
              </el-form-item>
            </td>
          </tr>
        </table>
        <table class="dateTable">
          <tr v-for="(eve, info) in 7" :key="info">
            <td>日期</td>
            <td>
              <el-date-picker
                v-model="applyForm.dateList[info]"
                type="date"
                placeholder="选择日期"
              >
              </el-date-picker>
            </td>
            <td>值班人</td>
            <td>
              <el-select
                v-model="applyForm.affactionList[info]"
                multiple
                placeholder="请选择值班人"
              >
                <el-option
                  v-for="item in createPeople"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </td>
          </tr>
          <td>备注</td>
          <td>
            <el-input
              v-model="applyForm.classRemark"
              placeholder="请输入备注"
            ></el-input>
          </td>
          <td>附件</td>
          <td>
            <el-form-item>
              <file-upload v-model="form.classAnnex" />
            </el-form-item>
          </td>
        </table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="applySubmit">保 存</el-button>
        <el-button @click="managecancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<style>
.dateTable td {
  padding: 10px 20px; /* 设置单元格的内边距 */
  text-align: center; /* 设置文本居中 */
  border: 1px solid black; /* 设置边框 */
}
</style>


<script>
import {
  listClass_manage,
  getClass_manage,
  delClass_manage,
  addClass_manage,
  updateClass_manage,
  applySend,
  getUsAndDe,
} from "@/api/eamp/class_manage";
import { extendChartView } from "echarts";
import { createPeople } from "@/api/eamp/car_list";
import { getDept } from "@/api/eamp/class_manage";
import { get } from "sortablejs";

export default {
  name: "Class_manage",
  data() {
    return {
      schedule: {
        周一: "",
        周二: "",
        周三: "",
        周四: "",
        周五: "",
        周六: "",
        周日: "",
      },
      // 遮罩层
      loading: true,

      tableData: [],

      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 排班值班关系表表格数据
      class_manageList: [],
      // 弹出层标题
      title: "",
      createPeople: [],
      getDept: [],
      // 是否显示弹出层
      open: false,
      applymange: false,
      viewMange:false,
      persons: [
        { id: 1, name: "PersonA" },
        { id: 2, name: "PersonB" },
        // Add more persons as needed
      ],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        className: null,
        classAffiliation: null,
        classCreatePeople: null,
        classCreateTime: null,
        delFlg: null,
        classUrgent: null,
        classRemark: null,
        classAnnex: null,
        dateId: null,
      },
      // 表单参数
      form: {
        dateList: [],
        affactionList: [],
      },
      applyForm: {
        dateList: [],
        affactionList: [],
      },
      viewForm:{
        dateList: [],
        affactionList: [],
      },
      // 表单校验
      rules: {},
      extent: [],
    };
  },
  created() {
    this.getList();
    this.queryCar();
    this.getmanage();
  },

  methods: {
    queryCar() {
      createPeople().then((res) => {
        if (res.code === 200) {
          this.createPeople = res.rows;
          console.log(this.createPeople);
        }
      });
    },
    getmanage() {
      getDept().then((response) => {
        console.log(response);

        this.getDept = response.rows;
      });
    },

    //提交排班申请
    applySubmit() {
      console.log(this.applyForm);
      applySend(this.applyForm).then((res) => {
        console.log(res);
      });
      this.applymange = false;
    },
    

    /** 查询排班值班关系表列表 */
    getList() {
      this.loading = true;
      getUsAndDe(this.queryParams).then((response) => {
        console.log(response.rows);
        
        this.class_manageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    //用户申请取消按钮
    managecancel() {
      this.applymange = false;
      this.reset;
    },
    // 表单重置
    reset() {
      this.form = {
        classId: null,
        className: null,
        classAffiliation: null,
        classCreatePeople: null,
        classCreateTime: null,
        delFlg: null,
        classUrgent: null,
        classRemark: null,
        classAnnex: null,
        dateId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.classId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加排班值班关系表";
    },
    handleview(row) {
      const classId = row.classId || this.ids;
      getClass_manage(classId).then((response) => {
        console.log(response);
        this.viewForm=response.data
        this.viewForm.classUrgent=response.data.classUrgent+''
        // this.form = response.data;
      });
      this.viewMange = true;
      this.viewForm = row;
    },

    //取消按钮
    manCancel() {
      this.viewMange = false;
      this.reset();
    },
    handleMange() {
      this.applymange = true;
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const classId = row.classId || this.ids;
      getClass_manage(classId).then((response) => {
        this.form = response.data;
        this.applymange = true;
        this.title = "修改排班值班关系表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.classId != null) {
            updateClass_manage(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addClass_manage(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const classIds = row.classId || this.ids;
      this.$modal
        .confirm('是否确认删除排班值班关系表编号为"' + classIds + '"的数据项？')
        .then(function () {
          return delClass_manage(classIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "eamp/class_manage/export",
        {
          ...this.queryParams,
        },
        `class_manage_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

